﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UNBP.Model;
using Portal.Web.Utility;

namespace Portal.Exam.Render
{
    public class UpdateMultiChoice : WebPart
    {
        public override string WebPartId
        {
            get
            {
                return "UpdateMultiChoice";
            }
        }

        public override string Title
        {
            get
            {
                return ResourceBLL.GetText(WebPartId,"Title","Cập nhật câu hỏi chọn nhiều phương án trả lời đúng");
            }
        }

        public override string Description
        {
            get
            {
                return ResourceBLL.GetText(WebPartId,"Description","");
            }
        }

        [AjaxPro.AjaxMethod]
        public string GetHtml(string QuestionId)
        {
            QuestionCls QuestionCls = new QuestionBll().CreateModel(QuestionId);
            if (QuestionCls == null)
            {
                return "Truy cập bị cấm đường dẫn không hợp lệ";
            }


            string[] Answer = new string[]{
                    "Đúng","Sai"
                };
            string[] AnswerCode = new string[]{
                    "Yes","No"
                };



            string MonthiId = (string)WebEnvironments.Request("MonthiId");
            string Type = (string)WebEnvironments.Request("Type");

            string RightAns = "";
            DataTable dtAnswers = new QuestionBll().ReadingAnswer(QuestionId);
            for (int iIndexAns = 0; iIndexAns < dtAnswers.Rows.Count; iIndexAns++)
            {
                string CorrectAnswer = "";
                try
                {
                    CorrectAnswer = (string)dtAnswers.Rows[iIndexAns]["CorrectAnswer"];
                }
                catch { }
                CorrectAnswer = CorrectAnswer.ToUpper();
                if (CorrectAnswer.Equals("YES"))
                {
                    try
                    {
                        RightAns = RightAns+(string)dtAnswers.Rows[iIndexAns]["AnswerTextFirst"]+";";
                    }
                    catch { }
                }
            }
            string BackUrl = Screen.BuildUrl(new Question().WebPartId, new ParamCls[]{
                    new ParamCls("BoMonId",QuestionCls.MonthiCls.BoMonCls.BoMonId),
                    new ParamCls("MonthiId",QuestionCls.MonthiCls.MonthiId),
                    new ParamCls("Type",QuestionCls.Type),
            });
            string SelectLevel =
                  "<select id=drpSelectLevelQuestion>\r\n" +
                  "   <option value=\"0\">Mức độ dễ</option>\r\n" +
                  "   <option value=\"1\">Mức độ trung bình</option>\r\n" +
                  "   <option value=\"2\">Mức độ khó</option>\r\n" +
                  "</select>\r\n";
            if (QuestionCls.Level == 1)
            {
                SelectLevel =
                  "<select id=drpSelectLevelQuestion>\r\n" +
                  "   <option value=\"0\">Mức độ dễ</option>\r\n" +
                  "   <option value=\"1\" selected>Mức độ trung bình</option>\r\n" +
                  "   <option value=\"2\">Mức độ khó</option>\r\n" +
                  "</select>\r\n";
            }
            if (QuestionCls.Level == 2)
            {
                SelectLevel =
                  "<select id=drpSelectLevelQuestion>\r\n" +
                  "   <option value=\"0\">Mức độ dễ</option>\r\n" +
                  "   <option value=\"1\">Mức độ trung bình</option>\r\n" +
                  "   <option value=\"2\" selected>Mức độ khó</option>\r\n" +
                  "</select>\r\n";
            }
            string RetHtml =
                 " <script language=javascript> \r\n" +
                 " function ClientSaveUpdateMultiChoiceQuestion (QuestionId) \r\n" +
                 "   { \r\n" +
                 "       Title=document.getElementById(\"txtQuestion\").value; \r\n" +
                 "       MaxPoint=document.getElementById(\"txtPoint\").value; \r\n" +
                 "       SecondTime = document.getElementById(\"txtSecondTime\").value; \r\n" +
                 "       IsMemory = document.getElementById(\"chkIsMemory\").checked; \r\n" +
                 "       SecondHidden = document.getElementById(\"txtSecondHidden\").value; \r\n" +
                 "       SelectLevelIndex = document.getElementById(\"drpSelectLevelQuestion\").selectedIndex; \r\n" +
                 "       SelectLevel = document.getElementById(\"drpSelectLevelQuestion\").options[SelectLevelIndex].value; \r\n" +
                 "       retValue=Portal.Exam.UpdateMultiChoice.ServerSideSaveQuestion(QuestionId,Title,MaxPoint,SecondTime,IsMemory,SecondHidden, SelectLevel).value; \r\n" +
                 "       if(retValue.indexOf(\"ERROR\")!=-1) \r\n" +
                 "       { \r\n" +
                 "           alert(retValue); \r\n" +
                 "           return; \r\n" +
                 "       } \r\n" +
                 "       window.open('"+BackUrl+"','_self'); \r\n" +
                 "   } \r\n" +

                 " function AddItemAnswerMultiChoice(QuestionId) \r\n" +
                 "   { \r\n" +
                 "       NewAnswerItem=document.getElementById(\"txtNewAnswerItem\").value; \r\n" +
                 "       retValue = Portal.Exam.UpdateMultiChoice.ServerSideAddNewAnswerItem(QuestionId,NewAnswerItem).value; \r\n" +
                 "       if(retValue.indexOf(\"ERROR\")!=-1) \r\n" +
                 "       { \r\n" +
                 "           alert(retValue); \r\n" +
                 "           return; \r\n" +
                 "       } \r\n" +
                 "       retValue=Portal.Exam.UpdateMultiChoice.GetHtml(QuestionId).value; \r\n" +
                 "       document.getElementById(\"divUpdateBestAnsContent\").innerHTML=retValue; \r\n" +
                 "       document.getElementById(\"txtNewAnswerItem\").focus(); \r\n" +
                 "   } \r\n" +

                 " function ClientDeleteAnsMuitiChoice(QuestionId,AnswerId)\r\n"+
                 "   {\r\n"+
                 "       Msg=Portal.Exam.UpdateMultiChoice.GetConfirmDeleteMsg().value;\r\n"+
                 "       if(confirm(Msg)==false)return;\r\n"+
                 "       retValue = Portal.Exam.UpdateMultiChoice.ServerSideDeleteAnswer(AnswerId).value;\r\n"+
                 "       if(retValue.indexOf(\"ERROR\")!=-1)\r\n"+
                 "       {\r\n"+
                 "           alert(retValue);\r\n"+
                 "           return;\r\n"+
                 "       }\r\n"+
                 "       retValue=Portal.Exam.UpdateMultiChoice.GetHtml(QuestionId).value;\r\n"+
                 "       document.getElementById(\"divUpdateBestAnsContent\").innerHTML=retValue;\r\n"+
                 "   }\r\n" +

                 " function MultiChoiceEditAnswerItemText(QuestionId,AnswerId) \r\n"+
                 "   { \r\n"+
                 "       Url=Portal.Exam.UpdateMultiChoice.GetUpdateAnsItemText(QuestionId,AnswerId).value; \r\n"+
                 "       if(Url.indexOf(\"ERROR\")!=-1) \r\n"+
                 "       { \r\n"+
                 "           alert(Url); \r\n"+
                 "           return; \r\n"+
                 "       } \r\n"+
                 "       window.open(Url, '_self'); \r\n"+
                 "       retValue=Portal.Exam.UpdateMultiChoice.GetHtml(QuestionId).value; \r\n"+
                 "       document.getElementById(\"divUpdateBestAnsContent\").innerHTML=retValue; \r\n"+
                 "   } \r\n" +


                 " function MultiChoiceSetRightAnsItem(QuestionId,AnswerId) \r\n" +
                 "   { \r\n" +
                 "       Msg=Portal.Exam.UpdateMultiChoice.GetConfirmSetRightAnsItem(AnswerId).value; \r\n" +
                 "       if(confirm(Msg)==false)return; \r\n" +
                 "       retValue=Portal.Exam.UpdateMultiChoice.ServerSideSetRightAnsItem(QuestionId,AnswerId).value; \r\n" +
                 "       if(retValue.indexOf(\"ERROR\")!=-1) \r\n" +
                 "       { \r\n" +
                 "           alert(retValue); \r\n" +
                 "           return; \r\n" +
                 "       } \r\n" +
                 "       alert(retValue); \r\n" +
                 "       retValue=Portal.Exam.UpdateMultiChoice.GetHtml(QuestionId).value; \r\n" +
                 "       document.getElementById(\"divUpdateBestAnsContent\").innerHTML=retValue; \r\n" +
                 "   } \r\n" +

                 " </script>\r\n"+
                 "      <table>" +
                 "         <tr>" +
                 "              <td class=cssUpdateBestAnsItemCol1>Mức độ</td>" +
                 "              <td>" + SelectLevel + "</td>" +
                 "         </tr>" +
                 "          <tr>" +
                 "              <td class=cssUpdateBestAnsItemCol1>" + ResourceBLL.GetText(WebPartId, "UpdateYesNoCaption", "Câu hỏi:") + "</td>" +
                 "              <td><textarea class=cssTextBoxQuestion id=txtQuestion>" + QuestionCls.Title + "</textarea></td>" +
                 "          </tr>" +
                 "          <tr>" +
                 "              <td>" + ResourceBLL.GetText(WebPartId, "Point", "Điểm:") + "</td>" +
                 "              <td><input id=txtPoint value=\"" + QuestionCls.MaxPoint + "\"></td>" +
                 "          </tr>" +
                 "          <tr>" +
                 "              <td>" + ResourceBLL.GetText(WebPartId, "SecondTime", "Thời gian(giây):") + "</td>" +
                 "              <td><input id=txtSecondTime value=\"" + QuestionCls.SecondTime + "\"></td>" +
                 "          </tr>" +
                 "          <tr>" +
                 "              <td>" + ResourceBLL.GetText(WebPartId, "Answer", "Đáp án:") + "</td>" +
                 "              <td>" + RightAns + "</td>" +
                 "          </tr>" +
                 "          <tr>" +
                 "              <td>" + ResourceBLL.GetText(WebPartId, "IsMemory", "Câu hỏi trí nhớ:") + "</td>" +
                 "              <td><input type=checkbox id=chkIsMemory " + (QuestionCls.IsMemory == 1 ? "CHECKED" : "") + " ></td>" +
                 "          </tr>" +
                 "          <tr>" +
                 "              <td>" + ResourceBLL.GetText(WebPartId, "SecondHidden", "Thời gian ẩn:") + "</td>" +
                 "              <td><input id=txtSecondHidden value=\"" + QuestionCls.SecondHidden + "\"></td>" +
                 "          </tr>" +
                 "         <tr>" +
                 "             <td></td>" +
                 "             <td></td>" +
                 "         </tr>" +
                 "</table>" +
                 "<div class=cssHeadingBestAns>" + ResourceBLL.GetText(WebPartId, "AnswerTable", "CÁC PHƯƠNG ÁN TRẢ LỜI") + "</div>" +
                 "<div class=cssHeadingAddItemBestAns><input class=cssNewAnswerItem id=txtNewAnswerItem><input onclick=javascript:AddItemAnswerMultiChoice('" + QuestionId + "'); type=button value=\"" + ResourceBLL.GetText(WebPartId, "AddAnsItem", "(Thêm phương án)") + "\"></div>";
            RetHtml += "<table>";
            for (int iIndexAns = 0; iIndexAns < dtAnswers.Rows.Count; iIndexAns++)
            {
                string AnswerTextFirst = "???";
                try
                {
                    AnswerTextFirst = (string)dtAnswers.Rows[iIndexAns]["AnswerTextFirst"];
                }
                catch { }
                string CorrectAnswer = "";
                try
                {
                    CorrectAnswer = (string)dtAnswers.Rows[iIndexAns]["CorrectAnswer"];
                }
                catch { }
                string AnswerId = (string)dtAnswers.Rows[iIndexAns]["AnswerId"];
                string ButtonSetText = "<input onclick=javascript:MultiChoiceSetWrongAnsItem('" + QuestionId + "','" + AnswerId + "'); type=button value=\"" + ResourceBLL.GetText(WebPartId, "SetWrongAnsItem", "=>pán sai") + "\">";
                CorrectAnswer = CorrectAnswer.ToUpper();
                string Class = " class=cssIncorrectAnsLine";
              
                if (CorrectAnswer.Equals("YES"))
                {
                    Class = " class=cssCorrectAnsLine";
                }
                else
                {
                    ButtonSetText = "<input onclick=javascript:MultiChoiceSetRightAnsItem('" + QuestionId + "','" + AnswerId + "'); type=button value=\"" + ResourceBLL.GetText(WebPartId, "SetRightAns", "=>pán đúng") + "\">";
                }

                RetHtml += "<tr>" +
                         "      <td class=cssUpdateBestAnsItemCol1 valgin=top align=right>" + ResourceBLL.GetText(WebPartId, "Pa", "pa.") + (iIndexAns + 1) + ":</td>" +
                         "      <td valgin=top>"+ButtonSetText+"</td>" +
                         "      <td valgin=top><input onclick=javascript:MultiChoiceEditAnswerItemText('" + QuestionId+"','"+AnswerId + "'); type=button value=\"" + ResourceBLL.GetText(WebPartId, "ModifyAns", "(Sửa)") + "\"></td>" +
                         "      <td valgin=top><input onclick=javascript:ClientDeleteAnsMuitiChoice('" + QuestionId + "','" + AnswerId + "'); type=button value=\"" + ResourceBLL.GetText(WebPartId, "DeleteAns", "(Xóa)") + "\"></td>" +
                         "      <td valgin=top><span" + Class + ">" + AnswerTextFirst + "</span></td>" +
                         "</tr>";

            }
            RetHtml += "</table>" +
                       "<div class=cssFunctionUpdateBestAns><input type=button  onclick=javascript:ClientSaveUpdateMultiChoiceQuestion('" + QuestionId + "'); value=\"" + ResourceBLL.GetText(WebPartId, "UpdateYesNoSaveButton", "Ghi lại") + "\"><input type=button  onclick=\"javascript:window.open('"+BackUrl+",'_self');\" value=\"" + ResourceBLL.GetText(WebPartId, "UpdateYesNoCancelButton", "Danh sách") + "\"></div>";

            string previewUrl = "PreviewOneQuestion.aspx?QuestionId=QuestionId";
            return RetHtml;
        }

        public override string RenderWebPart()
        {
            try
            {

                WebSessionUtility.CheckSessionTimeOut(); 

                //PermissionTypeCls PermissionTypeCls = WebEnvironments.FindPermissionType(new Question().PermissionTypes, "dkQuestion");
                //Environment.Permission.CheckPermission(WebEnvironments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "dkUpdateQuestion", new Question().WebPartId, null, true);

                string QuestionId = System.Web.HttpContext.Current.Request["QuestionId"];

                string RetHtml = "<div id=divUpdateBestAnsContent>"+ GetHtml(QuestionId)+"</div>";

                return RetHtml;
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        //[AjaxPro.AjaxMethod]
        //public string ServerSideUpdateYesNo(string QuestionId, string Title, int CorrectOrder, string MaxPoint, string SecondTime, string IsMemory, string SecondHidden)
        //{
        //    try
        //    {
        //        WebSessionUtility.CheckSessionTimeOut(); 
        //        PermissionTypeCls PermissionTypeCls = WebEnvironments.FindPermissionType(new Question().PermissionTypes, "dkQuestion");
        //        Environment.Permission.CheckPermission(WebEnvironments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "dkUpdateQuestion", new Question().WebPartId, null, true);

        //        if (Title.Trim().Length == 0) throw new Exception(ResourceBLL.GetText(WebPartId, "EnterName", "Nhập tên nhóm vai trò"));
        //        if (SharepointPortal.Environment.FuncUtilities.checkInteger(MaxPoint) == false) throw new Exception(ResourceBLL.GetText(WebPartId, "InvalidPoint", "Dữ liệu điểm nhập không hợp lệ! Phải nhập kiểu số!"));
        //        new QuestionBll().UpdateQuestionYesNo(null, QuestionId, Title,CorrectOrder,int.Parse(MaxPoint),int.Parse(SecondTime),bool.Parse(IsMemory),int.Parse(SecondHidden));
        //        return ResourceBLL.GetText(WebPartId,"MessageUpdateOk","Cập nhật thành công!");
        //    }
        //    catch (Exception ex)
        //    {
        //        return "ERROR: " + ex.Message.ToString();
        //    }
        //}



        [AjaxPro.AjaxMethod]
        public string ServerSideAddNewAnswerItem(
            string QuestionId,
            string NewAnswerItem)
        {
            try
            {
                WebSessionUtility.CheckSessionTimeOut(); 
                ////PermissionTypeCls PermissionTypeCls = WebEnvironments.FindPermissionType(new Question().PermissionTypes, "dkQuestion");
                ////Environment.Permission.CheckPermission(WebEnvironments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "dkUpdateQuestion", new Question().WebPartId, null, true);

                if (NewAnswerItem.Trim().Length == 0) throw new Exception(ResourceBLL.GetText(WebPartId, "InvalidNewAnsItem", "Chưa nhập phương án trả lời mới"));
                new QuestionBll().AddNewAnswerItem(null, QuestionId, NewAnswerItem);
                return ResourceBLL.GetText(WebPartId, "AddNewAnswerOk", "Thêm mới phương án trả lời thành công!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string GetConfirmDeleteMsg()
        {
            return ResourceBLL.GetText(WebPartId, "ConfirmDeleteMsg", "Bạn đã chắc chắn xóa chưa?");
        }

        [AjaxPro.AjaxMethod]
        public string GetConfirmSetRightAnsItem(string AnswerId)
        {
            try
            {
                AnswerCls AnswerCls = new QuestionBll().CreateModelAnswer(AnswerId);
                string retValue = ResourceBLL.GetText(WebPartId, "ConfirmSetRightAnsItem", "Bạn đã chắc chắn đặt câu trả lời [RightAnsText] là câu ĐÚNG chưa?");
                retValue = retValue.Replace("RightAnsText", AnswerCls.AnswerTextFirst);
                return retValue;
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string GetConfirmSetWrongAnsItem(string AnswerId)
        {
            try
            {
                AnswerCls AnswerCls = new QuestionBll().CreateModelAnswer(AnswerId);
                string retValue = ResourceBLL.GetText(WebPartId, "ConfirmSetWrongAnsItem", "Bạn đã chắc chắn đặt câu trả lời [WrongAnsText] là câu SAI chưa?");
                retValue = retValue.Replace("WrongAnsText", AnswerCls.AnswerTextFirst);
                return retValue;
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string ServerSideDeleteAnswer(
            string AnswerId)
        {
            try
            {
                WebSessionUtility.CheckSessionTimeOut(); 
                //PermissionTypeCls PermissionTypeCls = WebEnvironments.FindPermissionType(new Question().PermissionTypes, "dkQuestion");
                //Environment.Permission.CheckPermission(WebEnvironments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "dkUpdateQuestion", new Question().WebPartId, null, true);

                if (Title.Trim().Length == 0) throw new Exception("Nhập tên nhóm vai trò");
                new QuestionBll().DeleteAnswerItem(null, AnswerId);
                return "Xóa phương án trả lời thành công!";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string GetUpdateAnsItemText(
            string QuestionId,
            string AnswerId)
        {
            try
            {
                WebSessionUtility.CheckSessionTimeOut(); 
                //PermissionTypeCls PermissionTypeCls = WebEnvironments.FindPermissionType(new Question().PermissionTypes, "dkQuestion");
                //Environment.Permission.CheckPermission(WebEnvironments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "dkUpdateQuestion", new Question().WebPartId, null, true);
                return "EditAnswerItem.aspx?QuestionId=QuestionId&AnswerId="+AnswerId;
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string ServerSideSaveAnsItem(string AnswerId,string AnsText)
        {
            try
            {
                WebSessionUtility.CheckSessionTimeOut(); 
                PermissionTypeCls PermissionTypeCls = WebEnvironments.FindPermissionType(new Question().PermissionTypes, "dkQuestion");
                Environment.Permission.CheckPermission(WebEnvironments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "dkUpdateQuestion", new Question().WebPartId, null, true);
                if (AnsText.Trim().Length == 0) throw new Exception(ResourceBLL.GetText(WebPartId,"InvalidTitle","Chưa nhập nội dung phương án trả lời mới!"));
                new QuestionBll().SaveAnswerItem(null, AnswerId, AnsText);
                return ResourceBLL.GetText(WebPartId, "SaveItemOk", "Cập nhật nội dung phương án trả lời thành công!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

       
        [AjaxPro.AjaxMethod]
        public string ServerSideSetRightAnsItem(string QuestionId,string AnswerId)
        {
            try
            {
                WebSessionUtility.CheckSessionTimeOut(); 
                PermissionTypeCls PermissionTypeCls = WebEnvironments.FindPermissionType(new Question().PermissionTypes, "dkQuestion");
                Environment.Permission.CheckPermission(WebEnvironments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "dkUpdateQuestion", new Question().WebPartId, null, true);

                new QuestionBll().SetRightAnswerItem(null,QuestionId,  AnswerId,false);
                return ResourceBLL.GetText(WebPartId, "SetRightOk", "Đặt lại phương án trả lời đúng thành công!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public string ServerSideSetWrongAnsItem(string QuestionId, string AnswerId)
        {
            try
            {
                WebSessionUtility.CheckSessionTimeOut(); 
                PermissionTypeCls PermissionTypeCls = WebEnvironments.FindPermissionType(new Question().PermissionTypes, "dkQuestion");
                Environment.Permission.CheckPermission(WebEnvironments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "dkUpdateQuestion", new Question().WebPartId, null, true);

                new QuestionBll().SetWrongAnswerItem(null, QuestionId, AnswerId);
                return ResourceBLL.GetText(WebPartId, "SetWrong", "Đặt lại phương án trả lời SAI thành công!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public string ServerSideSaveQuestion(string QuestionId, string Title, int MaxPoint, int SecondTime, bool IsMemory, string SecondHidden, string SelectLevel)
        {
            try
            {
                WebSessionUtility.CheckSessionTimeOut(); 
                PermissionTypeCls PermissionTypeCls = WebEnvironments.FindPermissionType(new Question().PermissionTypes, "dkQuestion");
                Environment.Permission.CheckPermission(WebEnvironments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "dkUpdateQuestion", new Question().WebPartId, null, true);
                if (Title.Trim().Length == 0) throw new Exception(ResourceBLL.GetText(WebPartId, "InvalidQuestion", "Chưa nhập nội dung câu hỏi!"));
                new QuestionBll().SaveQuestion(null, QuestionId, Title, MaxPoint, "", SecondTime, IsMemory, int.Parse(SecondHidden),int.Parse(SelectLevel));
                return ResourceBLL.GetText(WebPartId, "SaveQuestionOk", "Cập nhật câu hỏi chọn nhiều câu trả lời thành công!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        } 
    }
}